/* -----------------------------------------------------------------------
 * Random tester for villager kingdom card
 * Include the following lines in your makefile:
 *
 * testVillageCard: testVillageCard.c dominion.o rngs.o
 *      gcc -o testVillageCard -g  testVillageCard.c dominion.o rngs.o $(CFLAGS)
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 0

//Random tester for village

//tests
//test draw card

//num action +2

//village discarded


int main(int argc, char *argv[])
{
	srand(time(NULL));
	
	int i, j;
    int seed = 1500;
    int numPlayer = rand() % 4;
	int tests = rand() % 40;
    int r;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int handCount = 5;
	int villages[MAX_HAND];
    for (i = 0; i < MAX_HAND; i++)
    {
        villages[i] = village;
    } 
	
	
	//begin tests
	printf("\nStarting village Card tests. Seed is %d\n", seed);
	for(i = 0; i < tests; i++){
		for(j = 0; j < numPlayer; j++){
		
			memset(&G, 23, sizeof(struct gameState));   // clear the game state
			r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
			memcpy(G.hand[j], villages, sizeof(int) * handCount); // set all the cards to village
			G.whoseTurn = j;
#if (NOISY_TEST == 1)
	printf("handCount: %d, deckCount: %d, phase: %d, whoseturn: %d\n", G.handCount[0], G.deckCount[0], G.phase, G.whoseTurn);
#endif
			
			r = playCard(0, 0, 0, 0, &G);		// call village effect
			
			//tests
#if (NOISY_TEST == 1)
	printf("cardEffect return is %d, expected 0.\n", r);	//drawCard's return
#endif
			assert(r == 0);
			
#if (NOISY_TEST == 1)
	printf("action count is %d, expected %d.\n", G.numActions, 2);
#endif
			assert(G.numActions == 2);
			
#if (NOISY_TEST == 1)
	printf("playedCardCount is %d, expected %d\n\n", G.playedCardCount, 1);
#endif
			assert(G.playedCardCount == 1);
		}
	}
	
	
	//use rngs instead
    //srand(time(NULL));
	
	printf("\tAll village card tests completed successfully...\n");
    return 0;                  
}                               
